var wae_setobj = null;
var eventSender_obj = null;
var isfocus = true;
var msg_obj = null;
var simpleFile_obj = null;
var wae_httpobj = null;
var intent_obj = null;
var netManager_obj = null;
var apps_obj = null;
var simpleFile_obj = null;//sd卡文件




var set_id = sessionStorage.getItem( "set_iid");
sessionStorage.setItem( "set_iid", "");
if(!set_id)
	set_id = "focusId";


function $(str) { return document.getElementById(str)}


var m_waeErrorHandler = null;
var m_returnCallback = null;
function openMessage(msg){
	/*m_returnCallback=null;
	if(arguments.length>1&&arguments[1])
		m_returnCallback = arguments[1];*/
		
	// if(!msg){
			// alert("==提示信息为空，请联系管理员！==")
			// return;
		// }
		// var _errorcode = m_tipsJson[msg];
		// if(!_errorcode){
			// alert("==未找到相应的错误代码，请联系管理员！==");
			// return;
		// }
		// m_waeErrorHandler.noticeErrorCode(_errorcode);

	alert(msg);
}
//启动时间机制,气温

window.onWAEReady = function(){
	
	if(wae.can("tools.ErrorHandler")&&wae.can("tools.ErrorHandler")==true){
		m_waeErrorHandler = wae.create("tools.ErrorHandler");
	}
	
	//弹出框返回处理函数
	m_waeErrorHandler.onErrorHandlerResult = function(e){
		var _returnCode = e.arguments[0];
		if(_returnCode==0)
			return;
			
		if(m_returnCallback)
				eval("("+m_returnCallback+")");
	}
	
	if(!SERVER_URL||SERVER_URL==null){
//		var msg = "请输入服务器地址";
//		openMessage(msg);
		
	}

	
	eventSender_obj = wae.create("EventSender");
	if (eventSender_obj == null) {
		console.log("FAIL: create EventSender  object null!");
	}
	//eventSender_obj.focus( document.getElementById(set_id).offsetLeft  , document.getElementById(set_id).offsetTop);
	
	wae_setobj = wae.create("plugins.SettingsExpands");
	
	
	VatataKeyMove.initVttKeymoveById($("focusId"));
	
	showVersion();
	VatataPublic.updatetime_Temperature($("weekId"),$("timeId"),$("temperatureId"),$("temperatureImgId"));
	//dateTimeInit();
}



/**
 * 显示版本号
 */

var application_obj = null;
//版本
function showVersion(){
	try{
	if(!application_obj){
		application_obj = wae.create("Application");
	}
	
	document.getElementById('versionName').innerText = 'ver '+application_obj.versionName() + '.' + HTML_PAGE_VERSION;
	}catch(e){}
}



function Settings(type){
	//alert('isfocus   '+isfocus)
	/*if(isfocus){
		isfocus = false;
		return;
	}*/
	var str = type+"Settings()";
	//alert('str   '+str)
	eval(str);

}

function ServerSettings(){
	sessionStorage.setItem( "set_iid", "ServerId");
	location.href = './serverset.html';
}

function ThemeSettings(){
	sessionStorage.setItem( "set_iid", "ThemeId");
	location.href = './wallpaper.html'; 
}

function WifiSettings(){
	wae_setobj.gotoWifiSettings();	
}

function NetSettings(){
	wae_setobj.getEthernetSettings();
}

function TimeSettings(){
	wae_setobj.gotoTimeSettings();
}

function DisplaySettings(){
	wae_setobj.gotoDisplaySettings();
}


//家长保护
function JiazhangSettings(){
	location.href = 'protect.html'; 	
}

//关于
var about_str = false;
function AboutSettings(){
	
	/*if($("aboutId").style.display=="none"){
		$("aboutId").style.display = "block";
	}else{
		$("aboutId").style.display = "none";	
	}
	about_str = true;*/
	
	location.href = "banben.html"

	
}


//增加授权服务
function LocalbossSettings(){
	try{
		var authUrl = SERVER_URL + 'index.php/api?action=getlocalboss';
		if(!wae_httpobj){
			wae_httpobj = wae.create("Net.HttpClient");
		}
		
		if(!intent_obj){
			intent_obj  = wae.create("Intent");
	
		}
		
		var auth_con = wae_httpobj.getWithSync(authUrl).toLocaleString();
		eval("authContent="+auth_con);
		var auth_url = authContent.auth_url; 
		
		if(!netManager_obj){
			netManager_obj = wae.create("Net.NetworkManager")
		}
		
		var netManager = netManager_obj.getNetInfo();
		
		var macnumber = netManager.match(/MAC:[\s\S]*?,/)[0].replace(/MAC:|,/g,'').replace(/:/g,'');
		var licensereg_url = auth_url + '/index.php/api/licensereg?device='+macnumber
		intent_obj.startBrowser(licensereg_url) ;

		
		
	}catch(e){
		alert("激活失败 请联系:sales@tvata.com");
	}
}



function OpenapkSettings(){
	//离线安装包版本
/*	apps_obj=wae.create("AppManager")
	try{
		var xmlContent = apps_obj.getInstalledApps();
		var xmlObj = (new DOMParser()).parseFromString(xmlContent, "application/xhtml+xml");
		var _xml_apps = xmlObj.getElementsByTagName("appdata");
		var a_name = '';
		var isUpdate = false;
		if (_xml_apps.length > 0) {
			for(i=0;i<_xml_apps.length;i++){
				a_name+=_xml_apps[i].getAttribute("apk_name");
				if(_xml_apps[i].getAttribute("apk_name")=="com.tvata.tvaofflineupdateinstaller"){
					isUpdate=true;	
				}
			}
		}
		if(isUpdate){
			if(!intent_obj){
				intent_obj = wae.create("Intent");
			}
			intent_obj.startActivity("com.tvata.tvaofflineupdateinstaller");	
		}else{
			alert("请到应用商店下载'恢复出厂安装包'");
		}
	}catch(e){}*/   
	
	//工厂版本
	var intent=wae.create("Intent");
	intent.setIntentAction("android.settings.BACKUP_AND_RESET_SETTINGS");
	intent.startActivity();
	
}



var key_times = 1;
window.onkeydown = function(){
	
	/*if(about_str==true){
		key_times ++;
		if(key_times>2){
			$("aboutId").style.display = "none";
			key_times = 1;
			about_str = false;
		}
	}*/
}




window.onbeforeunload = function(){
	VatataKeyMove.clearAllVttKey();
}


